<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var noticeTreeGrid;
    $(function() {
        noticeTreeGrid = $('#noticeTreeGrid').treegrid({
            url : '${path}/notice/treeGrid',
            idField : 'id',
            treeField : 'name',
            parentField : 'pid',
            fit : true,
            fitColumns : false,
            border : false,
            columns : [ [ 
                {
                width : '100',
                title : 'id',
                field : 'id'
                ,hidden : true
            },
                {
                width : '100',
                title : '接收部门',
                field : 'revOrgNames'
            },
                {
                width : '100',
                title : '标题',
                field : 'title'
            },
                {
                width : '100',
                title : '类型',
                field : 'type'
            },
                {
                width : '100',
                title : '公开',
                field : 'overt'
            },
                {
                width : '100',
                title : '接收部门id',
                field : 'revOrgids'
                ,hidden : true
            },
                {
                width : '100',
                title : '接收人id',
                field : 'revUserds'
                ,hidden : true
            },
                {
                width : '100',
                title : '内容',
                field : 'content'
            },
                {
                width : '100',
                title : '接收人',
                field : 'revUserNames'
            },
                {
                width : '100',
                title : '附件',
                field : 'attachIds'
            },
		{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="notice-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editNoticeFun(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="notice-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteNoticeFun(\'{0}\');" >删除</a>', row.id);
                     
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.notice-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.notice-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#noticeToolbar'
        });
    });
    
    function editNoticeFun(id) {
        if (id != undefined) {
            noticeTreeGrid.treegrid('select', id);
        }
        var node = noticeTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.modalDialog({
                title : '编辑',
                width : 500,
                height : 450,
                href : '${path}/notice/editPage/' + node.id,
                buttons : [ {
                    text : '编辑',
                    handler : function() {
                        parent.$.modalDialog.openner_treeGrid = noticeTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                        var f = parent.$.modalDialog.handler.find('#noticeEditForm');
                        f.submit();
                    }
                } ]
            });
        }
    }
    
    function deleteNoticeFun(id) {
        if (id != undefined) {
            noticeTreeGrid.treegrid('select', id);
        }
        var node = noticeTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.messager.confirm('询问', '您是否要删除'+node.name+'?', function(b) {
                if (b) {
                    progressLoad();
                    $.post('${path}/notice/delete/'+node.id, {
                    }, function(result) {
                        if (result.success) {
                            parent.$.messager.alert('提示', result.msg, 'info');
                            noticeTreeGrid.treegrid('reload');
                        }else{
                            parent.$.messager.alert('提示', result.msg, 'info');
                        }
                        progressClose();
                    }, 'JSON');
                }
            });
        }
    }
    
    function addNoticeFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 400,
            href : '${path}/notice/addPage',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_treeGrid = noticeTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#noticeAddForm');
                    f.submit();
                }
            } ]
        });
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false"  style="overflow: hidden;">
        <table id="noticeTreeGrid"></table>
    </div>
    <div id="noticeToolbar" style="display: none;">
            <a onclick="addNoticeFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </div>
</div>